package com.dongdong.service.impl;

import com.dongdong.mapper.TbItemCatMapper;
import com.dongdong.model.TbItemCat;
import com.dongdong.model.TbItemCatExample;
import com.dongdong.service.ItemCatService;
import com.dongdong.vo.ItemCatVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ItemCatServiceImpl implements ItemCatService {

    @Autowired
    private TbItemCatMapper tbItemCatMapper;

    @Override
    public List<ItemCatVO> FindItemCatList(Long pid) {
        TbItemCatExample tbItemCatExample = new TbItemCatExample();
        TbItemCatExample.Criteria criteria = tbItemCatExample.createCriteria();
        criteria.andParentIdEqualTo(pid);
        List<TbItemCat> tbItemCats = tbItemCatMapper.selectByExample(tbItemCatExample);
        List<ItemCatVO> collect = tbItemCats.stream().map((x) -> {
            ItemCatVO itemCatVO = new ItemCatVO();
            BeanUtils.copyProperties(x, itemCatVO);
            return itemCatVO;
        }).collect(Collectors.toList());
        return collect;
    }
}
